<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form action="" method="post">
			<table border="1" cellspacing="0" cellpadding="12px" id="tabid">
				<tr>
					<th></th>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>家庭住址</th>
			    </tr>
				<tr>
					<td><input type="checkbox" name="inputname1" id="inputid1" value="10" /></td>
					<td>阿刁</td>
					<td class="sex">男</td>
					<td>18</td>
					<td>江苏扬州</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>阿飒</td>
					<td class="sex">女</td>
					<td>19</td>
					<td>浙江嘉兴</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>阿呆</td>
					<td class="sex">男</td>
					<td>20</th>
					<td>内蒙古锡林郭勒盟</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>阿肆</td>
					<td class="sex">女</td>
					<td>21</td>
					<td>云南大理</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="" id="" value="" /></td>
					<td>阿嗨</td>
					<td class="sex">女</td>
					<td>20</td>
					<td>海南三亚</td>
				</tr>
			</table>
		</form>
		<input type="checkbox" name="" id="Allcheckid" value="" onclick="set_all()" />全选
		<input type="checkbox" name="" id="Allcheckboysid" value="" onclick="set_allboys()" />全选男
		<input type="checkbox" name="" id="Allcheckgirlsid" value="" onclick="set_allgirls()" />全选女
	</body>
	<script type="text/javascript">
		function set_all(){
			var tabidobj = document.getElementById('tabid')
			var inputall = tabidobj.getElementsByTagName('input')
			console.log(inputall)
			var Allcheckidvalue = document.getElementById('Allcheckid').checked
			console.log(Allcheckidvalue)
			for(var i=0;i<inputall.length;i++){
				inputall[i].checked = Allcheckidvalue;
			}
		}
		function set_allboys(){
			var allsex = document.getElementsByClassName('sex')
			for (var i=0;i<allsex.length;i++) {
				if(allsex[i].innerText == '男'){
					var tabidobj = document.getElementById('tabid')
					var inputall = tabidobj.getElementsByTagName('input')
					var Allcheckboysidvalue = document.getElementById('Allcheckboysid').checked
					inputall[i].checked = Allcheckboysidvalue;
				}
			}
		}
		function set_allgirls(){
			var allsex = document.getElementsByClassName('sex')
			for (var i=0;i<allsex.length;i++) {
				if(allsex[i].innerText == '女'){
					var tabidobj = document.getElementById('tabid')
					var inputall = tabidobj.getElementsByTagName('input')
					var Allcheckgirlsidvalue = document.getElementById('Allcheckgirlsid').checked
					inputall[i].checked = Allcheckgirlsidvalue;
				}
			}
		}
	</script>
</html>
